
#%%
data = [
  { "city": "石家庄", "type": "水果", "value": 14500 },
  { "city": "石家庄", "type": "米面", "value": 8500 },
  { "city": "石家庄", "type": "特产零食", "value": 10000 },
  { "city": "石家庄", "type": "茶叶", "value": 7000 },
  { "city": "深圳", "type": "水果", "value": 9000 },
  { "city": "深圳", "type": "米面", "value": 8500 },
  { "city": "深圳", "type": "特产零食", "value": 11000 },
  { "city": "深圳", "type": "茶叶", "value": 6000 },
  { "city": "温州", "type": "水果", "value": 16000 },
  { "city": "温州", "type": "米面", "value": 5000 },
  { "city": "温州", "type": "特产零食", "value": 6000 },
  { "city": "温州", "type": "茶叶", "value": 10000 },
  { "city": "宁波", "type": "水果", "value": 14000 },
  { "city": "宁波", "type": "米面", "value": 9000 },
  { "city": "宁波", "type": "特产零食", "value": 10000 },
  { "city": "宁波", "type": "茶叶", "value": 9000 },
  { "city": "无锡", "type": "水果", "value": 14000 },
  { "city": "无锡", "type": "米面", "value": 9000 },
  { "city": "无锡", "type": "特产零食", "value": 10000 },
  { "city": "无锡", "type": "茶叶", "value": 6000 },
  { "city": "杭州", "type": "水果", "value": 9000 },
  { "city": "杭州", "type": "米面", "value": 8500 },
  { "city": "杭州", "type": "特产零食", "value": 10000 },
  { "city": "杭州", "type": "茶叶", "value": 6000 },
  { "city": "北京", "type": "水果", "value": 17000 },
  { "city": "北京", "type": "米面", "value": 6000 },
  { "city": "北京", "type": "特产零食", "value": 7000 },
  { "city": "北京", "type": "茶叶", "value": 10000 },
  { "city": "上海", "type": "水果", "value": 18000 },
  { "city": "上海", "type": "米面", "value": 11000 },
  { "city": "上海", "type": "特产零食", "value": 15000 },
  { "city": "上海", "type": "茶叶", "value": 14000 }
]


set_options = {
  "appendPadding": 32,
  "data": data,
  "xField": "city",
  "yField": "value",
  "seriesField": "type",
  "isGroup": True,
  "columnStyle": {
    "radius": [20, 20, 0, 0],
  },
  "legend": {
    "position": "top"
  }
}
#%%

def form_html(key,key_type,data):
    if key == 'data':
        return ''
    print('form_html',key_type,type(key_type))
    if key_type == str:
        if key in ['xField','yField','seriesField']:
            return special_keyword(key,data)
        str_ = f'''
        <el-form-item label="{key}" prop="{key}" size="mini">
            <el-input v-model="{key}"></el-input>
        </el-form-item>
        '''
        return str_
    if key_type ==  bool:
        str_ = f'''
        <el-form-item label="{key}" prop="{key}">
            <el-switch v-model="{key}"></el-switch>
        </el-form-item>
        '''
        return str_
    
    if key_type == int or key_type == float :
        str_ = f'''
        <div class="block">
            <span class="demonstration">{key}</span>
            <el-slider
                v-model="{key}"
                show-input>
            </el-slider>
        </div>
        '''
        return str_
    
    return ''

def special_keyword(key,data):
    if key in ['xField','yField','seriesField']:
        str_ = f'''
        <el-form-item label="{key}">
        <el-select v-model="{key}" placeholder="请选择你的字段作为{key}轴">
        '''
        for data_key in data[0].keys():
            str_ += f'''
            <el-option label="{data_key}" value="{data_key}" />
            '''
        str_ += '''
            </el-select>
        </el-form-item>
        '''
        return str_


str_ = f'''
<el-form-item label="活动名称" prop="name">
    <el-input v-model="ruleForm.name"></el-input>
  </el-form-item>
'''
form_type={
    dict:"dict",
    int:"int",
    str:"str",
    list:'list',
    bool:'bool',
}

html_ = ""
for key in set_options.keys():
    if type(set_options[key]) ==dict:
        for key1 in set_options[key].keys():
            print(key1,type(set_options[key][key1]))
            html_ += form_html(f'{key}_{key1}',type(set_options[key][key1]),set_options['data'])
            print(form_html(f'{key}_{key1}',type(set_options[key][key1]),set_options['data']))
        continue
    print(key,type(set_options[key]))
    html_ += form_html(key,type(set_options[key]),set_options['data'])
    print(form_html(key,type(set_options[key]),set_options['data']))
# %%
html_.replace('\n','').strip()
# %%
